package com.lanyou.cook.util.gson;

import com.google.common.collect.Multimap;
import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;

public class PropertyWhiteListStrategy implements ExclusionStrategy {
	
	private final Multimap<Class<?>, String> nameMap;
	
	public PropertyWhiteListStrategy(Multimap<Class<?>, String> nameMap){
		this.nameMap = nameMap;
	}
	
	@Override
	public boolean shouldSkipField(FieldAttributes f) {
		return !nameMap.get(f.getDeclaringClass()).contains(f.getName());
	}

	@Override
	public boolean shouldSkipClass(Class<?> clazz) {
		return false;
//		return !nameMap.containsKey(clazz);
	}
}
